{extend name="base" /}
{block name="style"}
<style>
    .layui-form-select dl{min-width: 15%}
    .layui-select-title{width: 15%}
    .layui-form-select .layui-input{width:200px}
    .m-form .u-btn {margin:0;}
    .m-form-btn{margin:20px;text-align: center}
    .layui-textarea{width: 400px;}
</style>
{/block}
{block name="content"}
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}"><i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>运营</span>
            <span class="icon-angle-right"></span>
            <span>商户管理</span>
            <span class="icon-angle-right"></span>
            <span>{$info ? '编辑' : '添加'}商户</span>
            <a class="u-flush"><i class="icon-repeat"></i></a>
        </div>
    </div>

    <div class="m-main-content">
        <div class="m-container">
            <div class="m-form">
                <form class="layui-form" id="j_form">
                    <table class="m-table">
                        <thead>
                        <tr>
                            <th colspan="2"><?=$info ? '编辑' : '添加'?>商户</th>
                        </tr>
                        </thead>
                        <tbody>

                        <tr>
                            <td width="15%"><label for="contact_name">联系人姓名<em>*</em></label></td>
                            <td>
                                <input type="text" class="u-ipt u-ipt-long" name="contact_name" id="contact_name" placeholder="请输入联系人姓名" value="{$info['contact_name']}" />
                            </td>
                        </tr>

                        <tr>
                            <td width="15%"><label for="idcard_txt">身份证号</label></td>
                            <td>
                                <input type="text" class="u-ipt u-ipt-long" name="idcard_txt" id="idcard_txt" placeholder="请输入身份证号" value="{$info['idcard_txt']}" />
                            </td>
                        </tr>

                        <tr>
                            <td width="15%"><label for="">法人身份证</label></td>
                            <td>
                                <button type="button" class="layui-btn sxu-upload-pics" data-name="idcard_pics"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                                <div class="m-pics">
                                    <ul>
                                        {:s_attach_html($info.idcard_pics, 'idcard_pics', 'pics')}
                                    </ul>
                                </div>

                            </td>
                        </tr>

                        <tr>
                            <td width="15%"><label for="">营业执照</label></td>
                            <td>
                                <ul class="m-pic">

                                    <button type="button" class="layui-btn sxu-upload-pics" data-name="pics"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                                    <div class="m-pics">
                                        <ul>
                                            {:s_attach_html($info.pics,'pics','pics')}
                                        </ul>
                                    </div>
                                </ul>
                            </td>
                        </tr>

                        <tr>
                            <td><label for="">商户分类<em>*</em></label></td>
                            <td class="address">
                                <div class="layui-form-item">

                                    {volist name="t_arr" id="v"}
                                        <div class="layui-input-block" style="margin-left:5px">
                                             <input type="checkbox" name="category_id[]" title="{$v['name']}" {if isset($o_arr[$v["id"]])}checked{/if}  value="{$v.id}">
                                        </div>
                                        <div style="margin-left:50px">
                                            {volist name="v['sub_list']" id="sv"}
                                                    <input type="checkbox" name="type_id[]" title="{$sv['name']}" {if isset($sub_arr[$sv["id"]])}checked{/if} value="{$sv.id}">
                                            {/volist}
                                        </div>
                                    {/volist}

                                </div>
                            </td>
                        </tr>


                        <tr>
                            <td><label for="">机构地址<em>*</em></label></td>
                            <td class="address">
                                <div class="form-select" style="display: flex">
                                    <select name="province" lay-filter="province"></select>
                                    <select name="city" lay-filter="city"></select>
                                    <select name="district"></select>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label for="">机构详情地址<em>*</em></label></td>
                            <td class="">
                                <input type="text" class="u-ipt u-ipt-long" name="address"  placeholder="请输入详情地址" value="{$info['address']}" />
                            </td>
                        </tr>

                        <tr>
                            <td><label for="">机构地址<em>*</em></label></td>
                            <td>
                                <div>
                                    <input id="address" type="textbox" value=""  placeholder="请输入搜索内容哟">
                                    <a onclick="codeAddress()"><span style="border: 1px solid #ccc;background: #494E53;color: #fff;height: 20px;line-height: 18px;border-radius:3px;padding: 0 2px;" >search</span></a>
                                </div>
                                <div id="container" style="width:70%; height:400px"></div>
                            </td>
                        </tr>

                        <tr>
                            <td width="15%"><label>审核状态</label></td>
                            <td>{$info['status_txt']}</td>
                        </tr>
                        {if $info['status']==2}
                        <tr>
                            <td width="15%"><label>拒绝理由</label></td>
                            <td>{$info['remark']}</td>
                        </tr>
                        {/if}

                        </tbody>
                    </table>
                    <div class="m-form-btn">
                        <input type="hidden" name="id" value="<?=$info['id']?>">
                        <input type="hidden" name="lat" value="<?=$info['lat']?>">
                        <input type="hidden" name="lng" value="<?=$info['lng']?>">
                        <input type="hidden" name="status" value="1">
                        <button id="j_btn" class="u-btn u-submit-btn">通过</button>
                        <button id="refuse" class="u-btn u-submit-btn" style="background: #494E53">拒绝</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="extrajs"}
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=KAGBZ-DQVLU-EEBVC-255DO-5QYR2-JYBT3"></script>
<script src="__STATIC__/public/js/jquery-ui.min.js"></script>
{include file="public:upload"/}
{include file="public:editor"/}
<script>
    var geocoder,map,marker = null;
    $(function(){


        var url="{$redirect_uri}";
        $('input[name="redirect_uri"]').val(url)

        //初始化地图
        var center = new qq.maps.LatLng("{$info['lat']}","{$info['lng']}");
        map = new qq.maps.Map(document.getElementById('container'),{
            center: center,
            zoom: 15
        });

        new qq.maps.Marker({
            position: center,
            map: map
        });

        //调用地址解析类
        geocoder = new qq.maps.Geocoder({
            complete : function(result){
                // console.log(result)
                map.setCenter(result.detail.location);
                var marker = new qq.maps.Marker({
                    map:map,
                    position: result.detail.location
                });

                $("input[name='lat']").val(result.detail.location.lat);
                $("input[name='lng']").val(result.detail.location.lng);
                return false;
            }
        });

        layui.use(['layer', 'form'], function(){
            var layer  = layui.layer,
                form   = layui.form;
            var province_id ="{$info.province}";
            var city ="{$info.city}";
            var district ="{$info.district}";
            //城市三级联动
            var p_options="";
            var c_options="";
            var a_options="";
            $.getJSON("/static/data/address.json", "", function(data) {
                //each循环 使用$.each方法遍历返回的数据date
                $.each(data, function(i, item) {
                    // console.log(item)
                    p_options+="<option value='"+item.region_id+"'>"+item.region_name+"</option>";
                    if(item.region_id==province_id){
                        $.each(item.child, function(i, citem) {
                            c_options+="<option value='"+citem.region_id+"'>"+citem.region_name+"</option>";
                            if(citem.region_id==city){
                                $.each(citem.child, function(i, aitem) {
                                    a_options+="<option value='"+aitem.region_id+"'>"+aitem.region_name+"</option>";
                                });
                            }
                        });
                    }
                });

                //省
                $("select[name='province']").html(p_options);
                $("select[name='province'] option").attr("selected",false);
                $("select option[value='"+province_id+"']").attr("selected",true);

                $("select[name='city']").html(c_options);
                $("select[name='city'] option").attr("selected",false);
                $("select option[value='"+city+"']").attr("selected",true);

                $("select[name='district']").html(a_options);
                $("select[name='district'] option").attr("selected",false);
                $("select option[value='"+district+"']").attr("selected",true);

                form.render('select');
            });
        });
    });


    function codeAddress() {
        var address = document.getElementById("address").value;
        //通过getLocation();方法获取位置信息值
        geocoder.getLocation(address);
    }

    $("#refuse").click(function () {

        var edit_html="<div class=\"layui-form\" lay-filter=\"layuiadmin-form-useradmin\" id=\"layuiadmin-form-useradmin\" style=\"padding: 20px 0 0 0;\">\n" +

            "    <div class=\"layui-form-item\">\n" +
            "      <label class=\"layui-form-label\">理由</label>\n" +
            "      <div class=\"layui-input-inline\">\n" +
            "        <textarea  name=\"refuse\" class=\"layui-textarea\" style='400px'></textarea>\n" +
            "      </div>\n" +
            "    </div>\n" +
            "<div class=\"layui-layer-btn layui-layer-btn-\" style=\"text-align: center;\"> " +
            "<input type='hidden' name='id' value='{$info.id}'>"+
            " <button id=\"j_refuse\" class=\"u-btn\">确定提交</button></div></div>";


        layer.open({
            type: 1,
            title:'拒绝理由',
            shadeClose: true, //点击遮罩关闭
            area: ['600px', '300px'], //宽高
            content: edit_html
        });
        return false;
    });

    $("body").on("click","#j_refuse",function(){
        var refuse_txt=$("textarea[name='refuse']").val();
        var id=$("input[name='id']").val();

        $.post("/manage/stores/refuse",{id:id,refuse_txt:refuse_txt},function (res) {
            if(res.code==1){
                layer.msg(res.msg)
                setTimeout(function () {
                    layer.closeAll();
                    window.location.reload()
                },1000)
            }else{
                layer.msg(res.msg)
            }
        })
    })



</script>
{/block}